using System.Data;
using Common;
using DAL;
using Model;

namespace BLL {
    public class ProductBLL {
        private readonly ProductDAL _productDal = ProductDAL.GetInstance();

        private ProductBLL() {
        }

        private static ProductBLL _productBLL = new ProductBLL();

        public static ProductBLL GetInstance() {
            return _productBLL;
        }

        public DataTable GetAllProduct() {
            return _productDal.SelectAllProduct();
        }

        public DataTable GetProductByName(Product product) {
            return _productDal.SelectByName(product);
        }

        public DataTable GetProductByCatID(Product product) {
            return _productDal.SelectByCatID(product);
        }

        public Result<Product> DownProduct(Product product) {
            if (product.ProStock > 0) {
                product.ProStock -= 1;
                _productDal.Update(product);
                return Result<Product>.Ok();
            }
            return Result<Product>.Error();
        }

        public void UpProduct(Product product) {
            product.ProStock += 1;
            _productDal.Update(product);
        }
    }
}